package com.github.wxiaoqi.security.biz.modules.menuShow.biz;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.github.wxiaoqi.security.biz.modules.menuShow.entity.CmsMainMenu;
import com.github.wxiaoqi.security.biz.modules.menuShow.mapper.CmsMainMenuMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.cms.request.CmsQueryMainMenuParam;

import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * 小程序首页菜单列表
 *
 * @author chj
 * @email ${email}
 * @date 2018-09-03 11:09:22
 */
@Slf4j
@Service
public class CmsMainMenuBiz extends BaseBiz<CmsMainMenuMapper,CmsMainMenu> {
	
	
	public List<CmsMainMenu> getMenuList(CmsQueryMainMenuParam param) {
		log.info("查询小程序首页菜单列表，请求参数。。。{}"+param);
		Example example = new Example(CmsMainMenu.class);
		//1级菜单
		example.createCriteria().andEqualTo("level","1");
		List<CmsMainMenu> list = mapper.selectByExample(example);
		log.info("1级菜单。。。{}"+list);
		if (list != null && list.size() > 0) {
			for (CmsMainMenu cmsMainMenu : list) {
				Example example1 =new Example(CmsMainMenu.class);
				Criteria criteria = example1.createCriteria();
				criteria.andEqualTo("level", "2");
				criteria.andEqualTo("isShow", "0");
				criteria.andEqualTo("parentCode", cmsMainMenu.getCode());
				if (param.getPlatformId() != null && param.getPlatformId().length() > 0) {
					criteria.andEqualTo("platformId",param.getPlatformId());
				}
				List<CmsMainMenu> list1 = mapper.selectByExample(example1);
				log.info("2级菜单。。。{}"+list1);
				Map<String, Object> child = new HashMap<>();
				child.put(cmsMainMenu.getCode(), list1);
				cmsMainMenu.setChildren(child);
			}
		}
		log.info("查询小程序首页菜单列表, 响应参数。。。{}"+list);
		return list;
	}
}